package com.example.controller;

import com.example.entity.Floor;
import com.example.entity.Page.PageRequest;
import com.example.result.CommonResult;
import com.example.service.FloorService;
import com.example.utils.redis.RedisUtil;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @project: smart-property
 * @description: 房屋管理 controller 层
 * @author: cjq
 * @create: 2022-11-20 19:35
 **/
@RestController
@RequestMapping("/floor")
public class FloorController {
    @Autowired
    FloorService floorService;

    @Autowired
    RedisUtil redisUtil;

    Integer cid;

    /**
     * 储物室查重
     * @param floor
     * @param uid
     * @return
     */
    @GetMapping("/listLocker")
    public CommonResult listLocker(String floor,Integer uid){
        return CommonResult.ok(floorService.listLocker(floor,uid));
    }

    /**
     * 添加/修改房屋信息
     * @param floor
     * @return
     */
    @PostMapping("/saveFloorInfo")
    public CommonResult saveFloorInfo(@RequestBody Floor floor){
        String houseInfo ="houseInfo_"+this.cid;
        redisUtil.del(houseInfo);
        return CommonResult.ok(floorService.saveFloorInfo(floor));
    }

    /**
     * 储物室列表展示
     * @param floor
     * @param cid
     * @param pageRequest
     * @return
     */
    @GetMapping("/queryLockerInfo")
    public CommonResult queryLockerInfo(String floor, Integer uid,Integer cid, PageRequest pageRequest){
        this.cid = cid;
        return CommonResult.ok(floorService.queryLockerInfo(floor,uid,cid,pageRequest));
    }

    /**
     * 删除房屋信息
     * @param id
     * @return
     */
    @DeleteMapping("/delFloorInfo")
    public CommonResult delFloorInfo(Integer id){
        String houseInfo ="houseInfo_"+this.cid;
        redisUtil.del(houseInfo);
        return CommonResult.ok(floorService.delFloorInfo(id));
    }

    /**
     * 批量删除房屋信息
     * @param ids
     * @return
     */
    @PutMapping("/batchDel/{ids}")
    public CommonResult batchDel(@PathVariable Integer[] ids){
        String houseInfo ="houseInfo_"+this.cid;
        redisUtil.del(houseInfo);
        return CommonResult.ok(floorService.batchDel(ids));
    }

    /**
     * 房屋列表展示
     * @param purpose
     * @param building
     * @param pageRequest
     * @return
     */
    @GetMapping("/queryFloorInfo")
    public CommonResult queryFloorInfo(String purpose,String building,Integer cid,PageRequest pageRequest){
        return CommonResult.ok(floorService.queryFloorInfo(purpose,building,cid,pageRequest));
    }

    /**
     * 统计房屋
     * @param cid
     * @return
     */
    @GetMapping("/countFloor")
    public CommonResult countFloor(Integer cid){
        return CommonResult.ok(floorService.countFloor(cid));
    }
}
